package com.zhou.yuefan.activity;

import com.zhou.yuefan.R;
import com.zhou.yuefan.application.MyApplication;
import com.zhou.yuefan.db.DBManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.database.sqlite.SQLiteDatabase;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AlphaAnimation;
import android.widget.LinearLayout;

public class MainActivity extends Activity {


	private DBManager dbManager;
	private SQLiteDatabase db;
	private MyApplication myApplication;
	private SharedPreferences sp;
	Editor spEditor;
	LinearLayout ll_firstRaw,ll_white ;


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		myApplication = (MyApplication) getApplication();
		ll_firstRaw = (LinearLayout)findViewById(R.id.ll_firstRaw);
		ll_white = (LinearLayout)findViewById(R.id.ll_white);
		ll_white.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(MainActivity.this,FoodsActivity.class);
				startActivity(intent);
			}
		});
		OnClickListener listener = new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(MainActivity.this,MiLaucherActivity.class);
				startActivity(intent);
			}
		};
		ll_firstRaw.setOnClickListener(listener);

		sp = this.getSharedPreferences("firstLoad", MODE_PRIVATE);
		spEditor = sp.edit();
		dbManager = myApplication.getDBInstance();

		
		if (!myApplication.isDataBaseExist()) {

			dbManager.createDatabase();

		}

		int i = sp.getInt("LT", 0);// LoadTimes，加载次数
		spEditor.putInt("LT", i + 1);
		spEditor.commit();

	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	

	
	
	@Override
	protected void onDestroy() {
		
		super.onDestroy();
		/*
		 * if (db != null) { Log.i("db", "db关闭了"); db.close(); }
		 */
	}

}
